<%@ Page Language="C#" AutoEventWireup="false" MasterPageFile="~/Screens/ScreenMasterPage.master" %>
<asp:Content ContentPlaceHolderID="Head" runat="server">

	<script type="text/javascript">
		var _slides = null;
		var _sessionPath = "F:/Media/ISO2/PDC05/PDC05-2/DAT/DAT200_files";
		var _slidesDiv;
		var _slidesFrame;
		var _playerDiv;
		var _player;
		var _slidesDivState;
		var _slidesFrameState;
		var _playerDivState;
		var _playerState;
		var _viewMode = "normal";
		var _updateTimer = null;
		var _initialized = false;
		
		function window::onload()
		{
			screen.onShow.attach(this, this.onShowHide);
			screen.onHide.attach(this, this.onShowHide);
			screen.onKey.attach(this, this.onKey);
			screen.onCommand.attach(this, this.onCommand);

			_updateTimer = new window.top.Timer("PDCSessions.updateTimer", 1000);
			_updateTimer.onTimeout.attach(this, this.onUpdateTimeout);

			mainFrame.frameElement.style.width = document.body.clientWidth + "px";
			mainFrame.frameElement.style.height = document.body.clientHeight + "px";
			mainFrame.frameElement.onreadystatechange = onMainFrameReadyStateChange; 
			mainFrame.frameElement.src = "osh://localhost/file://" + _sessionPath + "/Default.htm";
		}
		function window::onunload()
		{
			_updateTimer.stop();
			_updateTimer = null;

			if(mainFrame.Uninitialize)
				mainFrame.Uninitialize();

			screen.onShow.detach(this, this.onShowHide);
			screen.onHide.detach(this, this.onShowHide);
			screen.onKey.detach(this, this.onKey);
			screen.onCommand.detach(this, this.onCommand);
		}
		function onShowHide()
		{
		}
		function onUpdateTimeout()
		{
			if(!_initialized) return;
			if(mainFrame.MediaPlayer_IsPlaying())
				osh.refresh();
		}
		function onKey(sender, event)
		{
			if(!_initialized) return;

			if(event.keyCode == window.top.Keys.VK_RETURN)
			{
				switchView();
			}
			else if(event.keyCode == window.top.Keys.VK_UP)
			{
				if(mainFrame.MediaPlayer_Previous)
					mainFrame.MediaPlayer_Previous();
			}
			else if(event.keyCode == window.top.Keys.VK_DOWN)
			{
				if(mainFrame.MediaPlayer_Next)
					mainFrame.MediaPlayer_Next();
			}
		}
		function onCommand(sender, event)
		{
			if(!_initialized) return;

			var commandLowerCase = event.command.toLowerCase();
			if(commandLowerCase == "play" || commandLowerCase == "pause")
			{
				if(mainFrame.MediaPlayer_IsPlaying())
				{
					_updateTimer.stop();
					mainFrame.MediaPlayer_Pause();
					setView("normal");
				}
				else
				{
					if(_viewMode == "normal")
						setView("minimized");
					mainFrame.MediaPlayer_Play();
					osh.show();
					_updateTimer.start();
				}
			}
			else if(commandLowerCase == "stop")
			{
				_updateTimer.stop();
				mainFrame.MediaPlayer_Stop();
				setView("normal");
			}
		}
		

		function onMainFrameReadyStateChange()
		{
			var srcElement = window.event.srcElement;
			if(srcElement.readyState != "complete")
				return;
			
			mainFrame.document.body.onload = onMainFrameBodyLoad;
		}
		
		function onMainFrameBodyLoad()
		{
			_slidesDiv = mainFrame.document.getElementById("SlidesDiv");
			_slidesFrame = mainFrame.document.getElementById("SlidesFrame");
			_playerDiv = mainFrame.document.getElementById("MediaPlayerDiv");
			_player = mainFrame.document.getElementById("MediaPlayer");


			mainFrame.Initialize();
			mainFrame.StartPresentation();
			_player.URL = _sessionPath + "/0Media.asx";
			mainFrame.MediaPlayer_Play();

			// Fix some design issues
			mainFrame.document.body.scroll = "no";
			mainFrame.document.getElementById("Misc2Div").runtimeStyle.zIndex = 0; // MS logo
			mainFrame.document.getElementById("HTML1Frame").style.width = "0px";

			_initialized = true;

			saveState();
			setView("minimized");
			setView("maximized");
			osh.show();
			osh.refresh();
			_updateTimer.start();
		}

		function saveState()
		{
			if(_slidesDivState) return;

			_slidesDivState = {};
			_slidesDivState.left = _slidesDiv.runtimeStyle.left;
			_slidesDivState.top = _slidesDiv.runtimeStyle.top;
			_slidesDivState.width = _slidesDiv.runtimeStyle.width;
			_slidesDivState.height = _slidesDiv.runtimeStyle.height;
			_slidesDivState.backgroundColor = _slidesDiv.runtimeStyle.backgroundColor;

			_slidesFrameState = {};	
			_slidesFrameState.left = _slidesFrame.runtimeStyle.left;
			_slidesFrameState.top = _slidesFrame.runtimeStyle.top;
			_slidesFrameState.width = _slidesFrame.runtimeStyle.width;
			_slidesFrameState.height = _slidesFrame.runtimeStyle.height;
			_slidesFrameState.position = _slidesFrame.runtimeStyle.position;

			_playerDivState = {};
			_playerDivState.left = _playerDiv.runtimeStyle.left;
			_playerDivState.top = _playerDiv.runtimeStyle.top;
			_playerDivState.width = _playerDiv.runtimeStyle.width;
			_playerDivState.height = _playerDiv.runtimeStyle.height;
			
			_playerState = {};
			_playerState.left = _player.runtimeStyle.left;
			_playerState.top = _player.runtimeStyle.top;
			_playerState.width = _player.runtimeStyle.width;
			_playerState.height = _player.runtimeStyle.height;
		}

		function restoreState()
		{
			if(!_slidesDivState) return;
			
			_slidesDiv.runtimeStyle.left = _slidesDivState.left;
			_slidesDiv.runtimeStyle.top = _slidesDivState.top;
			_slidesDiv.runtimeStyle.width = _slidesDivState.width;
			_slidesDiv.runtimeStyle.height = _slidesDivState.height;
			_slidesDiv.runtimeStyle.backgroundColor = _slidesDivState.backgroundColor;

			_slidesFrame.runtimeStyle.left = _slidesFrameState.left;
			_slidesFrame.runtimeStyle.top = _slidesFrameState.top;
			_slidesFrame.runtimeStyle.width = _slidesFrameState.width;
			_slidesFrame.runtimeStyle.height = _slidesFrameState.height;
			_slidesFrame.runtimeStyle.position = _slidesFrameState.position;

			_playerDiv.runtimeStyle.left = _playerDivState.left;
			_playerDiv.runtimeStyle.top = _playerDivState.top;
			_playerDiv.runtimeStyle.width = _playerDivState.width;
			_playerDiv.runtimeStyle.height = _playerDivState.height;

			_player.runtimeStyle.left = _playerState.left;
			_player.runtimeStyle.top = _playerState.top;
			_player.runtimeStyle.width = _playerState.width;
			_player.runtimeStyle.height = _playerState.height;
		}

		function switchView()
		{
			var newViewMode;
			if(_viewMode == "normal")
				newViewMode = "maximized";
			else if(_viewMode == "maximized")
				newViewMode = "minimized";
			else // if(_viewMode == "minimized")
				newViewMode = "maximized";
			
			setView(newViewMode);
		}

		function setView(newViewMode)
		{
			_viewMode = newViewMode;

			if(newViewMode == "normal")
			{
				restoreState();
			}
			else
			{	
				var left, top, width, height;
				
				if(newViewMode == "minimized")
				{
					left = Math.round(mainFrame.document.body.clientWidth * 2 / 3);
					top = Math.round(mainFrame.document.body.clientHeight * 2 / 3);
					width = Math.round(mainFrame.document.body.clientWidth / 3);
					height = Math.round(mainFrame.document.body.clientHeight / 3);
				}
				else // if(newViewMode == "maximized")
				{
					left = 0;
					top = 0;
					width = mainFrame.document.body.clientWidth;
					height = mainFrame.document.body.clientHeight;
				}
				
				mainFrame.document.body.scroll = "no";

				_slidesDiv.runtimeStyle.left = "0px";
				_slidesDiv.runtimeStyle.top = "0px";
				_slidesDiv.runtimeStyle.width = mainFrame.document.body.clientWidth + "px";
				_slidesDiv.runtimeStyle.height = mainFrame.document.body.clientHeight + "px";
				_slidesDiv.runtimeStyle.clip = "rect(auto auto auto auto)";
				_slidesDiv.runtimeStyle.backgroundColor = "#ff00ff";

				_slidesFrame.runtimeStyle.position = "absolute";
				_slidesFrame.runtimeStyle.left = left + "px";
				_slidesFrame.runtimeStyle.top = top + "px";
				_slidesFrame.runtimeStyle.width = width + "px";
				_slidesFrame.runtimeStyle.height = height + "px";

				_playerDiv.runtimeStyle.left = "0px";
				_playerDiv.runtimeStyle.top = "0px";

				_player.runtimeStyle.left = "0px";
				_player.runtimeStyle.top = "0px";
				_player.runtimeStyle.width = "4px";
				_player.runtimeStyle.height = "3px";
			}
		 }
	</script>

</asp:Content>
<asp:Content ContentPlaceHolderID="Body" runat="server">

<iframe id='mainFrame' style='position: absolute; top: 0px; left: 0px; width: 100%; height: 100%;'
	scrolling='no' frameborder='0' allowTransparency='true'
	src='about:blank'></iframe>

<!--
<div style="position: absolute; top: 0px; z-order: 1;">
	<input type="button" value="Show/Hide" onclick="switchView();" />
	<input type="button" value="Play" onclick="window.location.reload(true);" />
</div>
-->

</asp:Content>
